<template>
  <div id="paas_content">
    <el-dialog
      title="题目信息"
      :visible.sync="auditDialogShow"
      width="40%"
      center
      :before-close="handleClose"
    >
      <el-form
        ref="organizationReport"
        label-width="130px"
        label-position="right"
        :model="value"
      >
        <el-row>
          <el-col>
            <el-form-item label="题目:">
             <div>{{ rowData.title }}</div>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="题型:">
              <div v-if="rowData.question_type === 0">填空</div>
              <div v-else-if="rowData.question_type === 1">单选</div>
              <div v-else-if="rowData.question_type === 2">多选</div>
            </el-form-item>
          </el-col>
          <el-col v-if="rowData.question_type !== 0">
            <el-form-item label="选项:">
              <p :key="cont.id" v-for="cont in rowData.list">
                {{ cont.content }}
              </p>
            </el-form-item>
          </el-col>
          <!-- <el-col>
            <el-form-item
              label="驳回原因:"
              prop="reject_cause"
              :rules="[
                {
                  max: 50,
                  message: '不得超出50个字符',
                  trigger: 'blur'
                }
              ]"
            >
              <el-input type="textarea" v-model="value.reject_cause"></el-input>
            </el-form-item>
          </el-col> -->
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <button-page :button-list="dialogData.button"></button-page>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: ["auditDialogShow", "rowData", "dialogData"],
  name: "auditDialog",
  data() {
    return {
      value: {
        reject_cause: ""
      }
    };
  },
  methods: {
    handleClose() {
      this.$emit("getDialogStatus");
    },
    //通过
    agree_btn(btn) {
      this.$refs["organizationReport"].validate(valid => {
        if (valid) {
          this.rowData.audit_status = 2;
          let obj = Object.assign({}, this.rowData);
          obj.list = JSON.stringify(obj.list);
          this.$post(btn.uri, obj).then(res => {
            if (res.data.state === "ok") {
              this.$message.success(res.data.message);
              this.$emit("getDialogStatus", true);
            } else {
              this.$message.error(res.data.message);
            }
          });
        }
      });
    },
    //拒绝
    refuse_btn(btn) {
      this.$refs["organizationReport"].validate(valid => {
        if (valid) {
          // this.rowData.audit_status = 3;
          // this.rowData.reject_cause = this.value.reject_cause;
          // let obj = Object.assign({}, this.rowData);
          // obj.list = JSON.stringify(obj.list);
          // this.$post(btn.uri, obj).then(res => {
          //   if (res.data.state === "ok") {
          //     this.$message.success(res.data.message);
          //     this.$emit("getDialogStatus", true);
          //   } else {
          //     this.$message.error(res.data.message);
          //   }
          // });
          this.$prompt('请输入驳回原因', '驳回原因', {
            inputPlaceholder: '请输入驳回理由',
            confirmButtonText: '确定驳回',
            cancelButtonText: '取消',
            inputErrorMessage: '不得超出50个字符',
            inputValidator: (value) => {       // 点击按钮时，对文本框里面的值进行验证
              if(!value) {
                return '驳回理由不能为空';
              }if(value.length>50){
                return '不得超出50个字符';
              }
            },
            callback: (action, instance) => {
              if(action === 'confirm') {
                this.rowData.audit_status = 3;
                this.rowData.reject_cause = instance.inputValue;
                let obj = Object.assign({}, this.rowData);
                obj.list = JSON.stringify(obj.list);
                this.$post(btn.uri, obj).then(res => {
                  if (res.data.state === "ok") {
                    this.$message.success(res.data.message);
                    this.$emit("getDialogStatus", true);
                  } else {
                    this.$message.error(res.data.message);
                  }
                });
              }else{
                this.$message({
                  type: 'info',
                  message: '取消驳回'
                });
              }
            }
          });
        }
      });
    }
  }
};
</script>

<style scoped></style>
